﻿#ifndef HASHMAP_H
#define HASHMAP_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <pthread.h>


#define TABLE_SIZE 1024  // 哈希表的大小

typedef struct Node {
    char key[32];  // 假设键的最大长度为31
    void* value;
    struct Node* next;
} Node;

typedef struct {
    Node* buckets[TABLE_SIZE];
    pthread_mutex_t locks[TABLE_SIZE];
} HashMap;


unsigned int hash(const char* key);
void init_hash_map(HashMap* map);
void insert_or_update(HashMap* map, const char* key, void* value);
void* find(HashMap* map, const char* key);
void hash_delete(HashMap* map, const char* key);  // 重命名 delete 为 hash_delete
void free_hash_map(HashMap* map);

#endif // HASHMAP_H